package com.skyward.android.androiddemo2;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.skyward.android.androiddemo2.bean.TimeLineBean;
import com.skyward.android.androiddemo2.view.CircleTimeLineView2;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class TimeLine extends AppCompatActivity {

    private ListView mTimeLine_lv;
    private List<TimeLineBean> mTimeLineBeanList;
    private Random mRandom;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_time_line);
        mTimeLine_lv = (ListView) findViewById(R.id.timeLine_lv);
        mRandom = new Random();
        mTimeLineBeanList = new ArrayList<>();
        initData();
        mTimeLine_lv.setAdapter(new myAdapter());



    }

    private void initData() {
        for (int i = 0; i < 30; i++) {
            mTimeLineBeanList.add(new TimeLineBean("标题"+i,"3/15"));
        }
    }

    class myAdapter extends BaseAdapter{

        @Override
        public int getCount() {
            return mTimeLineBeanList.size();
        }

        @Override
        public Object getItem(int position) {
            return mTimeLineBeanList.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view =View.inflate(TimeLine.this,R.layout.time_line_item,null);
            TextView textView = (TextView) view.findViewById(R.id.tv_title);
            CircleTimeLineView2 circleTimeLineView2 = (CircleTimeLineView2) view.findViewById(R.id.timeLineContent);
            textView.setText(mTimeLineBeanList.get(position).getTitle());
            circleTimeLineView2.setText(mTimeLineBeanList.get(position).getTime());
            circleTimeLineView2.setColor(Color.rgb(100+mRandom.nextInt(155),100+mRandom.nextInt(155),100+mRandom.nextInt(155)));
            return view;
        }
    }

}
